/*
 * @Author: zhaiyujia
 * @Date: 2022-11-16 00:43:31
 * @LastEditors: zhaiyujia
 * @LastEditTime: 2022-11-19 15:56:51
 * @Description: uart test.
 */

#include "Arduino.h"

typedef struct MyObject
{
    uint8_t field1;
    uint16_t field2;
    uint32_t field3;
    int field4;
    float field5;
    char string[10];
} Config;

Config cfg = {0xff, 0xffff, 0xffffffff, -255, PI, "Hello!"};
uint32_t count = 0;

void setup()
{
    char a[10] = "aaaaa";
    char b[10] = "bbbbb";

    Serial_begin(115200);
    delay(1500); // Wait for STC-ISP to open the serial port
    Serial_println("Hello Arduino-STC.");
    Serial_printf("cfg[%u]: %u,%u,%lu,%d,%f,%s\r\n", (u16)sizeof(cfg),
                  (u16)cfg.field1, cfg.field2, cfg.field3, cfg.field4, cfg.field5, cfg.string);
}
void loop()
{
    Config cfg2;
    cfg.field1 = count % 0xff;
    cfg.field2 -= count;
    cfg.field3 -= count;
    cfg.string[6] = 'A' + count % 26;

    eeprom_put(&cfg, sizeof(cfg));
    eeprom_get(&cfg2, sizeof(cfg2));

    Serial_printf("cfg2[%u]: %u,%u,%lu,%d,%f,%s\r\n", (u16)sizeof(cfg2),
                  (u16)cfg2.field1, cfg2.field2, cfg2.field3, cfg2.field4, cfg2.field5, cfg2.string);
    count++;
    delay(2000);
}